﻿Imports DCM
Imports DCM_Http
Imports System.Data

Public Module SQLData_Main
#Region "公共变量"
    Public CaoZuoRen As String = ""
    Public CaoZuoRen_BuMen As String = ""
    Public CaoZuoRen_ID As Integer = 0
    Public CaoZuoRen_MAC As String = ""
    Public ServerIP As String = ""
    Public ServerPort As Integer = 0
    Public ServerIP_Style As DCM.Enum_ServerIPStyle
    Public AppRndID As Long = 0
    Public ConnectApp As DCM.Enum_ConnectApp = DCM.Enum_ConnectApp.WinForm
    Public AppVersionNumber As DCM.Stru_Version
#End Region


#Region "SQL_GetGroupByArray"
    Public Function SQL_GetGroupByArray(GroupColumnName As String,
                                        TableName As String,
                                        DCM_CN As DCM_CN,
                                        Optional FilterStr As String = "",
                                        Optional IsShowProcessForm As Boolean = True) As String()
        Dim Rs As New List(Of String)
        Dim WhereStr As String = If(FilterStr = "", "", " where " & FilterStr)
        Dim sqlStr As String = String.Format("select {0} from {1}  group by {0} order by {0} desc", GroupColumnName, TableName)
        Dim DT As DataTable = SQL_Get_DataTable(sqlStr, DCM_CN)
        For Each DR In DT.Rows
            Rs.Add(DCM.CaseDBNullToString(DR(0)))
        Next
        Return Rs.ToArray
    End Function
#End Region
#Region "SQL_DataTable_To_DataBase"
    Public Function SQL_DataTable_To_DataBase(Table_Name As String,
                                  ByRef DV_THis As DataView,
                                 DCM_CN As DCM_CN, Optional IsShowProcessForm As Boolean = True,
                                  Optional 合并提交SQLstr As String = "") As Integer
        Return BctchAdd_To_DateBase(DV_THis.ToTable, DCM_CN, Table_Name, IsShowProcessForm, , , , 合并提交SQLstr)
    End Function
    Public Function SQL_DataTable_To_DataBase(Table_Name As String,
                                ByRef DT_THis As DataTable,
                               DCM_CN As DCM_CN, Optional IsShowProcessForm As Boolean = True,
                               Optional 合并提交SQLstr As String = "") As Integer
        Return BctchAdd_To_DateBase(DT_THis, DCM_CN, Table_Name, IsShowProcessForm, , , , 合并提交SQLstr)
    End Function
    Public Function BctchAdd_To_DateBase(ByRef DT_This As DataTable, ByVal DCM_CN As DCM_CN,
                                         TBName_This As String,
                                         Optional IsShowProcessForm As Boolean = True, Optional TimeOut As Integer = 300,
                                         Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                                         Optional ShowMessageStr As ShowMessageStr_D = Nothing,
                                         Optional 合并提交SQLstr As String = "") As Integer
        If DT_This.Rows.Count = 0 Then Return 0
        Dim InCount As Integer = 0
        Select Case DCM_CN.DCMHttp_Enum_ConnectStyle
            Case DCMHttp_Enum_ConnectStyle.DataBase
                Throw New Exception("Xamarin不支持直接操作数据库")
            Case DCMHttp_Enum_ConnectStyle.DCM_HttpListenServer_DataBase
                Return GetObjectFromHttpServer_SQLServer(DCMHttp_Enum_RequestType.DataTable_To_DataBase, ServerIP, ServerPort, TBName_This,
                                             DCM_CN.DCM_SQLServer_DataBase,
                                            DCM_CN.DCMHttp_Enum_ConnectStyle, DT_This, CaoZuoRen, CaoZuoRen_ID,
                                            TimeOut, , "数据表" & TBName_This & "批量导入", YaSuoFangShi, ShowMessageStr, 合并提交SQLstr)

            Case Else
                Throw New Exception("对不起,暂时不支持" & DCM_CN.DCMHttp_Enum_ConnectStyle.ToString & "的数据批量导入")
        End Select
    End Function
#End Region
#Region "SQL_Get_DataSet"
    Public Function SQL_Get_DataSet_ForInsert(SQLStr As String,
                               DCM_CN As DCM_CN,
                               Optional TimeOut As Integer = 300,
                               Optional ID_Name As String = "ID", Optional CaoZuoNeiRong As String = "",
                               Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                               Optional ShowMessageStr As ShowMessageStr_D = Nothing) As String()
        Dim DS As DataSet = SQL_Get_DataSet(SQLStr, DCM_CN, TimeOut, ID_Name, CaoZuoNeiRong, YaSuoFangShi, ShowMessageStr)
        Dim Rs As New List(Of String)
        For i As Integer = 0 To DS.Tables.Count - 1
            Dim DT = DS.Tables(i)
            For j As Integer = 0 To DT.Rows.Count - 1
                Dim Thisrs As String = DCM.CaseDBNullToString((DT.Rows(j)(0)))
                Rs.Add(Thisrs)
            Next
        Next
        Return Rs.ToArray
    End Function
    Public Function SQL_Get_DataSet(SQLStr As String,
                               DCM_CN As DCM_CN,
                               Optional TimeOut As Integer = 300,
                               Optional ID_Name As String = "ID", Optional CaoZuoNeiRong As String = "",
                               Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                               Optional ShowMessageStr As ShowMessageStr_D = Nothing) As DataSet
        Select Case DCM_CN.DCMHttp_Enum_ConnectStyle
            Case DCMHttp_Enum_ConnectStyle.None
                Throw New Exception("连接对象的类型不能为none!")
            Case DCMHttp_Enum_ConnectStyle.DataBase
                Throw New Exception("Xamarin不支持直接操作数据库")
            Case DCMHttp_Enum_ConnectStyle.DCM_HttpListenServer_DataBase
                Return GetObjectFromHttpServer_SQLServer(DCMHttp_Enum_RequestType.GetDataSet, ServerIP, ServerPort, SQLStr,
                                             DCM_CN.DCM_SQLServer_DataBase, DCM_CN.DCMHttp_Enum_ConnectStyle, Nothing,
                                             CaoZuoRen, CaoZuoRen_ID, TimeOut, ID_Name, CaoZuoNeiRong, YaSuoFangShi, ShowMessageStr)
            Case Else
                Throw New Exception("不支持的" & DCM_CN.DCMHttp_Enum_ConnectStyle.ToString & "数据库方法")
        End Select
    End Function
#End Region
#Region "SQL_Get_DataTable"
    Public Sub SQL_Get_DataTable(ByRef DT_This As DataTable,
                             Table_Name As String,
                             Filterstring As String,
                             DCM_CN As DCM_CN,
                             Optional TopNum As Integer = -1,
                             Optional ColumnsNames() As String = Nothing,
                             Optional OrderOrGroupstring As String = "",
                             Optional TimeOut As Integer = 300,
                             Optional ID_Name As String = "ID",
                             Optional CaoZuoNeiRong As String = "",
                             Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                             Optional ShowMessageStr As ShowMessageStr_D = Nothing)
        Dim SQLStr As String = SQLStr_Select(Table_Name, Filterstring, TopNum, ColumnsNames, OrderOrGroupstring, DCM_CN.DataBaseType)
        DT_This = SQL_Get_DataTable(SQLStr, DCM_CN, TimeOut, ID_Name, CaoZuoNeiRong, YaSuoFangShi, ShowMessageStr)
    End Sub
    Public Sub SQL_Get_DataTable(ByRef DT_This As DataTable,
                                SQLStr As String,
                                DCM_CN As DCM_CN,
                                Optional TimeOut As Integer = 300,
                                Optional ID_Name As String = "ID", Optional CaoZuoNeiRong As String = "",
                                Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                                Optional ShowMessageStr As ShowMessageStr_D = Nothing)
        DT_This = SQL_Get_DataTable(SQLStr, DCM_CN, TimeOut, ID_Name, CaoZuoNeiRong, YaSuoFangShi, ShowMessageStr)
    End Sub
    Public Function SQL_Get_DataTable(Table_Name As String,
                               Filterstring As String,
                               DCM_CN As DCM_CN,
                               Optional TopNum As Integer = -1,
                               Optional ColumnsNames() As String = Nothing,
                               Optional OrderOrGroupstring As String = "",
                               Optional TimeOut As Integer = 300,
                               Optional ID_Name As String = "ID",
                               Optional CaoZuoNeiRong As String = "",
                               Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                               Optional ShowMessageStr As ShowMessageStr_D = Nothing) As DataTable
        Dim SQLStr As String = SQLStr_Select(Table_Name, Filterstring, TopNum, ColumnsNames, OrderOrGroupstring, DCM_CN.DataBaseType)
        Return SQL_Get_DataTable(SQLStr, DCM_CN, TimeOut, ID_Name, CaoZuoNeiRong, YaSuoFangShi, ShowMessageStr)
    End Function
    Public Function SQL_Get_DataTable(SQLStr As String,
                                 DCM_CN As DCM_CN,
                                 Optional TimeOut As Integer = 300,
                                 Optional ID_Name As String = "ID", Optional CaoZuoNeiRong As String = "",
                                 Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                                 Optional ShowMessageStr As ShowMessageStr_D = Nothing) As DataTable
        Select Case DCM_CN.DCMHttp_Enum_ConnectStyle
            Case DCMHttp_Enum_ConnectStyle.None
                Throw New Exception("连接对象的类型不能为none!")
            Case DCMHttp_Enum_ConnectStyle.DataBase
                Throw New Exception("Xamarin不支持直接操作数据库")
            Case DCMHttp_Enum_ConnectStyle.DCM_HttpListenServer_DataBase
                Return GetObjectFromHttpServer_SQLServer(DCMHttp_Enum_RequestType.GetDataTable, ServerIP, ServerPort, SQLStr,
                                             DCM_CN.DCM_SQLServer_DataBase, DCM_CN.DCMHttp_Enum_ConnectStyle, Nothing,
                                             CaoZuoRen, CaoZuoRen_ID, TimeOut, ID_Name, CaoZuoNeiRong, YaSuoFangShi, ShowMessageStr)
            Case Else
                Throw New Exception("不支持的" & DCM_CN.DCMHttp_Enum_ConnectStyle.ToString & "数据库方法")
        End Select
    End Function
#End Region
#Region "SQL_Insert"
    Public Function SQL_Insert(SQLStr As String,
                               DCM_CN As DCM_CN,
                                Optional ID_Name As String = "ID",
                                Optional TimeOut As Integer = 30,
                                Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                                Optional ShowMessageStr As ShowMessageStr_D = Nothing) As String
        Select Case DCM_CN.DCMHttp_Enum_ConnectStyle
            Case DCMHttp_Enum_ConnectStyle.None
                Throw New Exception("连接对象的类型不能为none!")
            Case DCMHttp_Enum_ConnectStyle.DataBase
                Throw New Exception("Xamarin不支持直接操作数据库")
            Case DCMHttp_Enum_ConnectStyle.DCM_HttpListenServer_DataBase
                Return GetObjectFromHttpServer_SQLServer(DCMHttp_Enum_RequestType.Insert, ServerIP, ServerPort, SQLStr,
                                             DCM_CN.DCM_SQLServer_DataBase,
                                             DCM_CN.DCMHttp_Enum_ConnectStyle, Nothing, CaoZuoRen, CaoZuoRen_ID, TimeOut, ID_Name, , YaSuoFangShi, ShowMessageStr)
            Case Else
                Throw New Exception("不支持的" & DCM_CN.DCMHttp_Enum_ConnectStyle.ToString & "数据库方法")
        End Select
    End Function

    Public Function SQL_Insert(Table_Name As String,
                            InsertColumns As String,
                            InsertValues As String,
                             DCM_CN As DCM_CN,
                              Optional ID_Name As String = "ID",
                              Optional TimeOut As Integer = 30,
                               Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                                Optional ShowMessageStr As ShowMessageStr_D = Nothing) As String
        Dim SQLStr As String = SQLSr_Insert(Table_Name, InsertColumns, InsertValues)
        Return SQL_Insert(SQLStr, DCM_CN, ID_Name, TimeOut, YaSuoFangShi, ShowMessageStr)
    End Function
    Public Function SQL_Insert(Table_Name As String,
                              InsertColumns() As String,
                              InsertValues() As String,
                               DCM_CN As DCM_CN,
                                Optional ID_Name As String = "ID",
                                Optional TimeOut As Integer = 30,
                                 Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                                Optional ShowMessageStr As ShowMessageStr_D = Nothing) As String
        Dim SQLStr As String = SQLSr_Insert(Table_Name, InsertColumns, InsertValues)
        Return SQL_Insert(SQLStr, DCM_CN, ID_Name, TimeOut, YaSuoFangShi, ShowMessageStr)
    End Function
#End Region
#Region "SQL_Update"
    Public Function SQL_Update(Table_Name As String,
                                UpdateColumns() As String,
                                UpdateValues() As String,
                                 Filterstring As String,
                                 DCM_CN As DCM_CN,
                                 Optional TimeOut As Integer = 30) As Integer
        Dim SQLStr As String = SQLSr_Update(Table_Name, UpdateColumns, UpdateValues, Filterstring)
        Return SQL_Update(SQLStr, DCM_CN, TimeOut)
    End Function
    Public Function SQL_Update(Table_Name As String,
                             UpdateStr As String,
                             Filterstring As String,
                             DCM_CN As DCM_CN,
                                 Optional TimeOut As Integer = 30) As Integer
        Dim SQLStr As String = SQLSr_Update(Table_Name, UpdateStr, Filterstring)
        Return SQL_Update(SQLStr, DCM_CN, TimeOut)
    End Function
    Public Function SQL_Update(SQLStr As String, DCM_CN As DCM_CN,
                                 Optional TimeOut As Integer = 30,
                                 Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                                 Optional ShowMessageStr As ShowMessageStr_D = Nothing) As Integer
        Return SQL_Effect(SQLStr, DCM_CN, TimeOut, YaSuoFangShi, ShowMessageStr)
    End Function
#End Region
#Region "SQL_Effect"
    Public Function SQL_Effect(SQLStrs As List(Of String),
                              DCM_CN As DCM_CN,
                              Optional TimeOut As Integer = 30,
                              Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                              Optional ShowMessageStr As ShowMessageStr_D = Nothing) As Integer
        If IsNothing(SQLStrs) Then Throw New Exception("SQLStrs未初始化!")
        If SQLStrs.Count = 0 Then Return 0
        Dim SQLStr = String.Join(vbCrLf, SQLStrs)
        Return SQL_Effect(SQLStr, DCM_CN, TimeOut, YaSuoFangShi, ShowMessageStr)

    End Function
    Public Function SQL_Effect(SQLStr As String,
                               DCM_CN As DCM_CN,
                               Optional TimeOut As Integer = 30,
                               Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                               Optional ShowMessageStr As ShowMessageStr_D = Nothing) As Integer
        Select Case DCM_CN.DCMHttp_Enum_ConnectStyle
            Case DCMHttp_Enum_ConnectStyle.None
                Throw New Exception("连接对象的类型不能为none!")
            Case DCMHttp_Enum_ConnectStyle.DataBase
                Throw New Exception("Xamarin不支持直接操作数据库")
            Case DCMHttp_Enum_ConnectStyle.DCM_HttpListenServer_DataBase
                Return GetObjectFromHttpServer_SQLServer(DCMHttp_Enum_RequestType.Effect, ServerIP, ServerPort, SQLStr,
                                             DCM_CN.DCM_SQLServer_DataBase,
                                             DCM_CN.DCMHttp_Enum_ConnectStyle, Nothing, CaoZuoRen, CaoZuoRen_ID, TimeOut, , , YaSuoFangShi, ShowMessageStr)
            Case Else
                Throw New Exception("不支持的" & DCM_CN.DCMHttp_Enum_ConnectStyle.ToString & "数据库方法")
        End Select
    End Function
    Public Function SQL_Delete(Table_Name As String,
                               Filterstring As String,
                               DCM_CN As DCM_CN,
                               Optional TimeOut As Integer = 30,
                                Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                                Optional ShowMessageStr As ShowMessageStr_D = Nothing) As Integer
        Dim SQLStr As String = DCM.SQLStr_Delete(Table_Name, Filterstring)
        Return SQL_Effect(SQLStr, DCM_CN, TimeOut, YaSuoFangShi, ShowMessageStr)
    End Function
    Public Function SQL_Delete(SQLStr As String,
                              DCM_CN As DCM_CN,
                              Optional TimeOut As Integer = 30,
                               Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                               Optional ShowMessageStr As ShowMessageStr_D = Nothing) As Integer
        Return SQL_Effect(SQLStr, DCM_CN, TimeOut, YaSuoFangShi, ShowMessageStr)
    End Function
#End Region
#Region "SQL_GetObject"
    Public Function SQL_GetCount(TBName As String, Filter As String,
                                 DCM_CN As DCM_CN, Optional TimeOut As Integer = 30,
                             Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                             Optional ShowMessageStr As ShowMessageStr_D = Nothing) As Integer
        Dim SQlstr As String = "select count(*) from " & TBName & " where " & Filter
        Return SQL_GetCount(SQlstr, DCM_CN, TimeOut, YaSuoFangShi, ShowMessageStr)
    End Function
    Public Function SQL_GetCount(SQLStr As String,
                                DCM_CN As DCM_CN, Optional TimeOut As Integer = 30,
                            Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                            Optional ShowMessageStr As ShowMessageStr_D = Nothing) As Integer
        Dim OB As Object = SQL_GetObject(SQLStr, DCM_CN, TimeOut, YaSuoFangShi, ShowMessageStr)
        Return DCM.CaseDBNullToAppointDataType(OB, GetType(Integer))
    End Function
    Public Function SQL_GetObject(SQLStr As String,
                               DCM_CN As DCM_CN,
                               Optional TimeOut As Integer = 30,
                               Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                               Optional ShowMessageStr As ShowMessageStr_D = Nothing) As Object
        Select Case DCM_CN.DCMHttp_Enum_ConnectStyle
            Case DCMHttp_Enum_ConnectStyle.None
                Throw New Exception("连接对象的类型不能为none!")
            Case DCMHttp_Enum_ConnectStyle.DataBase
                Throw New Exception("Xamarin不支持直接操作数据库")
            Case DCMHttp_Enum_ConnectStyle.DCM_HttpListenServer_DataBase

                Return GetObjectFromHttpServer_SQLServer(DCMHttp_Enum_RequestType.GetObject, ServerIP, ServerPort, SQLStr,
                                             DCM_CN.DCM_SQLServer_DataBase,
                                             DCM_CN.DCMHttp_Enum_ConnectStyle, Nothing, CaoZuoRen, CaoZuoRen_ID, TimeOut, , , YaSuoFangShi, ShowMessageStr)
            Case Else
                Throw New Exception("不支持的" & DCM_CN.DCMHttp_Enum_ConnectStyle.ToString & "数据库方法")
        End Select
    End Function
    'Public Function SQL_Delete(Table_Name As String,
    '                          Filterstring As String,
    '                          DCM_CN As DCM_CN,
    '                          Optional TimeOut As Integer = 30,
    '                           Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
    '                           Optional ShowMessageStr As ShowMessageStr_D = Nothing) As Object
    '    Dim SQLStr As String = SQLStr_Delete(Table_Name, Filterstring)
    '    Return SQL_GetObject(SQLStr, DCM_CN, TimeOut, YaSuoFangShi, ShowMessageStr)
    'End Function
    'Public Function SQL_GetObject(Table_Name As String,
    '                           Filterstring As String,
    '                           DCM_CN As DCM_CN,
    '                           Optional TimeOut As Integer = 30,
    '                            Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
    '                            Optional ShowMessageStr As ShowMessageStr_D = Nothing) As Object
    '    Dim SQLStr As String = SQLStr_Delete(Table_Name, Filterstring)
    '    Return SQL_GetObject(SQLStr, DCM_CN, TimeOut, YaSuoFangShi, ShowMessageStr)
    'End Function
#End Region
#Region "SQL_GetObject_DataType"
#Region "数值型"
    Function SQL_GetIntegerBySQL(SQLStr As String, DCM_CN As DCM_CN, Optional TimeOut As Integer = 30,
                                 Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                                 Optional ShowMessageStr As ShowMessageStr_D = Nothing) As Integer
        'If InStr(SQLStr, "今日经验") > 0 Then
        '    Dim j = 1
        'End If
        Dim OB As Object = SQL_GetObject(SQLStr, DCM_CN, TimeOut, YaSuoFangShi, ShowMessageStr)
        Return DCM.CaseDBNullToAppointDataType(OB, GetType(Integer))
    End Function
    Function SQL_GetLongBySQL(SQLStr As String, DCM_CN As DCM_CN, Optional TimeOut As Integer = 30,
                              Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                              Optional ShowMessageStr As ShowMessageStr_D = Nothing) As Long
        Dim OB As Object = SQL_GetObject(SQLStr, DCM_CN, TimeOut, YaSuoFangShi, ShowMessageStr)
        Return DCM.CaseDBNullToAppointDataType(OB, GetType(Long))
    End Function
    Function SQL_GetSingleBySQL(SQLStr As String, DCM_CN As DCM_CN, Optional TimeOut As Integer = 30,
                                Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                                Optional ShowMessageStr As ShowMessageStr_D = Nothing) As Single
        Dim OB As Object = SQL_GetObject(SQLStr, DCM_CN, TimeOut, YaSuoFangShi, ShowMessageStr)
        Return DCM.CaseDBNullToAppointDataType(OB, GetType(Single))
    End Function
    Function SQL_GetDoubleBySQL(SQLStr As String, DCM_CN As DCM_CN, Optional TimeOut As Integer = 30,
                                Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                                Optional ShowMessageStr As ShowMessageStr_D = Nothing) As Double
        Dim OB As Object = SQL_GetObject(SQLStr, DCM_CN, TimeOut, YaSuoFangShi, ShowMessageStr)
        Return DCM.CaseDBNullToAppointDataType(OB, GetType(Double))
    End Function
#End Region
#Region "字符"
    Function SQL_GetStrBySQL(SQLStr As String, DCM_CN As DCM_CN, Optional TimeOut As Integer = 30,
                             Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                             Optional ShowMessageStr As ShowMessageStr_D = Nothing) As String
        Dim OB As Object = SQL_GetObject(SQLStr, DCM_CN, TimeOut, YaSuoFangShi, ShowMessageStr)
        Return DCM.CaseDBNullToAppointDataType(OB, GetType(String))
    End Function
#End Region
#Region "日期"
    Function SQL_GetDateBySQL(SQLStr As String, DCM_CN As DCM_CN, Optional TimeOut As Integer = 30,
                              Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                              Optional ShowMessageStr As ShowMessageStr_D = Nothing) As Date
        Dim OB As Object = SQL_GetObject(SQLStr, DCM_CN, TimeOut, YaSuoFangShi, ShowMessageStr)
        Return DCM.CaseDBNullToAppointDataType(OB, GetType(Date))
    End Function
#End Region
#End Region
#Region "方法转换，兼容之前的调用方法"
    Function GetObjectFromHttpServer_SQLServer(DCMHttp_Enum_RequestType As DCMHttp_Enum_RequestType,
                                               ServerIP As String,
                                                   ServerPort As Integer,
                                                   SQLStr As String,
                                                   DCMHttp_Enum_DataBaseName As DCMHttp_Enum_DataBaseName,
                                                   DCMHttp_Enum_ConnectStyle As DCMHttp_Enum_ConnectStyle,
                                                   Data As Object,
                                                   CaoZuoRen As String,
                                                   CaoZuoRen_ID As Integer,
                                                   Timeout As Integer,
                                                   Optional ID_Name As String = "ID",
                                                   Optional CaoZuoNeiRong As String = "",
                                                   Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                                                   Optional ShowMessageStr As ShowMessageStr_D = Nothing,
                                                   Optional Data_1 As Object = Nothing) As Object
        '设置要调用的接口      
        Dim SendRecord As New DCM_HttpListen_Record()
        SendRecord.Data = Data
        SendRecord.Data_1 = Data_1
        SendRecord.DCMHttp_Enum_RequestType = DCMHttp_Enum_RequestType
        SendRecord.DCMHttp_Enum_DataBaseName = DCMHttp_Enum_DataBaseName
        SendRecord.DCMHttp_Enum_ConnectStyle = DCMHttp_Enum_ConnectStyle
        SendRecord.Message = SQLStr
        SendRecord.TimeOut = Timeout
        SendRecord.IDName = ID_Name
        GetDataFromServer.SetSendRecordCaoZuoren(SendRecord, CaoZuoNeiRong)
        Return GetObjectFromHttpServer_SQLServer(SendRecord, ServerIP, ServerPort, YaSuoFangShi, ShowMessageStr)
    End Function
    Function GetObjectFromHttpServer_SQLServer(SendRecord As DCM.DCM_HttpListen_Record,
                                            ServerIP As String,
                                            ServerPort As Integer,
                                            Optional YaSuoFangShi As Enum_CS_数据压缩方式 = Enum_CS_数据压缩方式.序列化压缩,
                                            Optional ShowMessageStr As ShowMessageStr_D = Nothing) As Object
        Try
            Using WC As New Net.WebClient
                WC.Encoding = System.Text.Encoding.UTF8
                Dim Buff_Send() As Byte = GetByteFromHttpRecord(SendRecord, YaSuoFangShi)
                Dim ob = GetHttpRecordFromByte(Buff_Send, YaSuoFangShi, GetType(DCM.DCM_HttpListen_Record))
                Dim FF As String = DCM.Enum_URL_调用服务器方法.GetDataFromServerDataBase.ToString
                Dim PQ = System.Web.HttpUtility.ParseQueryString(String.Empty, System.Text.Encoding.UTF8)
                PQ(Enum_URL_传入参数.YaSuoFangShi.ToString) = YaSuoFangShi
                Dim URL As String = GetURLStr(ServerIP, ServerPort, FF, PQ)
                ShowMessageStr_Sub(ShowMessageStr, "正在向服务器请求数据", True, False)
                Dim Buff_Get() = WC.UploadData(URL, Buff_Send)
                ShowMessageStr_Sub(ShowMessageStr, "已完成数据接收,正在重建数据模型", False, False)
                Using dt_r As DCM.DCM_HttpListen_Record = GetHttpRecordFromByte(Buff_Get, YaSuoFangShi, GetType(DCM.DCM_HttpListen_Record))
                    Return GetObjectFromHttpServer_SQLServer_ReturnDll(dt_r)
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        Finally
            ShowMessageStr_Sub(ShowMessageStr, "", True, True)
        End Try
    End Function
    Private Sub ShowMessageStr_Sub(ShowMessageStr_D As ShowMessageStr_D, MessageStr As String, SuggestTittle As Boolean, SuggestClose As Boolean)
        If ShowMessageStr_D Is Nothing Then Return
        ShowMessageStr_D(MessageStr, SuggestTittle, SuggestClose)
    End Sub
#End Region
End Module


